<template>
    <div class="update-birthday">
      <van-datetime-picker
        v-model="currentDate"
        @cancel="$emit('close')"
        @confirm="onConfirm"
        type="date"
        title="选择年月日"
        :min-date="minDate"
        :max-date="maxDate"
      />
    </div>
</template>
<script>
import dayjs from 'dayjs'
import {
    updateUserProfile
  } from '@/api/user'
export default {
   props:{
     value:{
       type:String,
       required:true
     }
   },
   data() {
      return {
        minDate: new Date(1900, 0, 1),
        maxDate: new Date(),
        currentDate: new Date(this.value),
      }
   },
   methods: {
      async onConfirm() {
        this.$toast.loading({
          message: '保存中',
          forbidclick: true // 禁止背景点击
        })
        // const date = `${this.currentDate.getFullYear()}-${this.currentDate.getMonth() +1}-${this.currentDate.getDate()}}`
        const date =dayjs(this.currentDate).format('YYYY-MM-DD')
        await updateUserProfile({
            birthday: date
          })
          this.$toast.success('保存成功')
          this.$emit('input', date)
          this.$emit('close')
      },
   }
}
</script>
<style scoped>
</style>

